﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataInfo;
using KenLib.BusinessManager;
using System.Collections.Generic;
using System.IO;
using System.Web.Services;
using System.Linq;
using System.Drawing;
using System.Drawing.Imaging;


public partial class JOINT_frmJ_StaffBasicInfoInput : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((JOINT_MstPage_JOINT)this.Master).changeTitle("基本情報登録");
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("frmJ_StaffBasicInfoInput");
        //khuc nay xoa cache browser khong luu giu gia tri da insert truoc do neu truong hop nguoi dung nhan 
        //  back browser 
        Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();

        ////////////////////////////////////////////
        if (Session["役"] == null || Session["役"].ToString() == "")
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        addCss();
        if (ful_写真.HasFile)
        {
            flg3.Value = ful_写真.PostedFile.FileName;
        }
        if (!Page.IsPostBack)
        {

            this.Page.Title = "fghghfhfg";
            if (Session["役"] == null)
            {
                Response.Redirect("~/frmD_Login.aspx");
            }
            bind国籍();
            btn_次.Enabled = false;
            this.CheckUpdate();
            if (Session["ModeUpdateStaffBasicInfoInput"] != "Update" && Session["役"] != null)
            {
                ShowHiddenForPanel(false);
                int 役 = Convert.ToInt32(Session["役"].ToString());
                if (役 == 1)
                {
                    div企業名.Visible = true;
                    ddl_企業名.Focus();
                    bind企業名();
                }
                else
                {
                    txt_人コード.Focus();
                }
                Image2.Visible = false;
            }
        }
        if (Session["企業コード_2"] != null)
        {
            if (Session["企業コード_2"].ToString() != "")
            {
                login.Value = Session["企業コード_2"].ToString();
                txt_人コード.Focus();
            }
        }
        showError();
    }
    public void showError()
    {//  cac phuong thuc gan ma loi
        RequiredFieldValidator14.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator1.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator2.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator3.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator4.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator5.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator6.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator7.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator性別.ErrorMessage = GetError("ER00007");
        RequiredFieldValidator8.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator9.ErrorMessage = GetError("ER00007");
        RequiredFieldValidator10.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator11.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator12.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator13.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator17.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator20.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator22.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator企業名.ErrorMessage = GetError("ER00007");
        CustomValidator1.ErrorMessage = GetError("ER00009");
        CustomValidatorID番号.ErrorMessage = GetError("ER00009");
        Customvalidate2.ErrorMessage = GetError("ER00005");
        CustomValidator4.ErrorMessage = GetError("ER00005");
        CustomValidator5.ErrorMessage = GetError("ER00005");
        CustomValidator6.ErrorMessage = GetError("ER00005");
        CustomValidator8.ErrorMessage = GetError("ER00005");
        CustomValidatorHo.ErrorMessage = GetError("ER00002");
        CustomValidatorTen.ErrorMessage = GetError("ER00002");
        CustomValidator2.ErrorMessage = GetError("ER00006");
        CustomValidator10.ErrorMessage = GetError("ER00006");
        CustomValidatorkiemtrangaycapCMND.ErrorMessage = GetError("ER00005");
        CustomValidator11.ErrorMessage = GetError("ER00006");
        CustomValidator12.ErrorMessage = GetError("ER00006");
        CustomValidator14.ErrorMessage = GetError("ER00006");
        CustomValidator16.ErrorMessage = GetError("ER00002");
        //  CustomValidator16.ErrorMessage = GetError("ER00002");
        CustomValidator17.ErrorMessage = GetError("ER00002");
        CustomValidator18.ErrorMessage = GetError("ER00002");
        CustomValidator19.ErrorMessage = GetError("ER00002");
        //   CustomValidator20.ErrorMessage = GetError("ER00002");
        ///CustomValidator21.ErrorMessage = GetError("ER00002");
        //  CustomValidator22.ErrorMessage = GetError("ER00002");
        CustomValidator23.ErrorMessage = GetError("ER00002");
        //   CustomValidator24.ErrorMessage = GetError("ER00002");
        CustomValidator25.ErrorMessage = GetError("ER00002");
        CustomValidator7.ErrorMessage = GetError("ER00002");
        CustomValidator9.ErrorMessage = GetError("ER00002");
        FileUpLoadValidator.ErrorMessage = GetError("ER00002");
        RegularExpressionValidator1.ErrorMessage = GetError("ER00002");
        cusTomMinlenghパスポート番号.ErrorMessage = GetError("ER00002");
        customMinlengID番号.ErrorMessage = GetError("ER00002");
        RegularExpressionValidatorEmail2.ErrorMessage = GetError("ER00002");
        RegularExpressionValidatorEmail1.ErrorMessage = GetError("ER00002");
        CustomValidator13.ErrorMessage = GetError("ER00009");
        CustomValidator15.ErrorMessage = GetError("ER00009");
        CustomValidator20.ErrorMessage = GetError("ER00009");
    }
    protected void CustomValidator1FileSize(object source, ServerValidateEventArgs args)
    {
        if (ful_写真.FileBytes.Length > 500)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }
    protected void btn_リセット_Click(object sender, EventArgs e)
    {

        txt_人コード.Text = "";
        if (Session["ModeUpdateStaffBasicInfoInput"] == "Update")
            Session.Add("clearAllMode", 1);// gan session nay de xet che do clear tat ca
        Response.Redirect("frmJ_StaffBasicInfoInput.aspx");
    }
    protected void btn_戻る_Click(object sender, EventArgs e)
    {
        Session["clearAllMode"] = null;
        if (Session["ModeUpdateStaffBasicInfoInput"] != null)
        {
            Session["ModeUpdateStaffBasicInfoInput"] = null;
            Response.Redirect("frmJ_EmpBasicInfo.aspx");
        }
        else
        {
            Response.Redirect("frmJ_MCompManager.aspx");
        }
    }
    protected void btn_次_Click(object sender, EventArgs e)
    {
        Session["clearAllMode"] = null;//xoa di  du lieu o tat ca control
        Session["ModeUpdateStaffBasicInfoInput"] = null;
        Session["ModeUpdateStaffEnterInput"] = "Update";
        Session["ModeUpdateStaffDegreeByCompInput"] = "Update";
        Response.Redirect("frmJ_StaffEnterInput.aspx");
    }
    protected void btn_登録_Click(object sender, EventArgs e)
    {
        if (CustomValidator13.IsValid && CustomValidator15.IsValid)
        {

            if (ful_写真.HasFile)// check file size upload 
            {
                HttpPostedFile myFile = ful_写真.PostedFile;
                int nFileLen = myFile.ContentLength;

                double kb = nFileLen / 1024;
                if (kb > 500)
                {
                    string codeErr = "写真" + GetError("ER00019");

                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('" + codeErr + "');</script>", false);

                    return;
                }
            }
            ViewState["css"] = 1;//gan bien de lam bold cac label o mode xac nhan
            ((JOINT_MstPage_JOINT)this.Master).changeTitle("基本情報登録（確認）");
            this.Page.Title = "基本情報登録（確認）";
            flg2.Value = "1";
            // may khuc duoi nay gan du lieu nhap tu control vao  obj
            基本情報 obj = new 基本情報();
            obj.人コード = HttpUtility.HtmlEncode(txt_人コード.Text);
            obj.名 = HttpUtility.HtmlEncode(txt_名.Text);
            obj.姓 = HttpUtility.HtmlEncode(txt_姓.Text);
            obj.フリガナ姓 = HttpUtility.HtmlEncode(txt_フリガナ姓.Text);
            obj.フリガナ名 = HttpUtility.HtmlEncode(txt_フリガナ名.Text);
            obj.英字姓 = HttpUtility.HtmlEncode(txt_英字姓.Text);
            obj.英字名 = HttpUtility.HtmlEncode(txt_英字名.Text);
            obj.旧漢字 = HttpUtility.HtmlEncode(txt旧姓漢字.Text);
            obj.旧姓フリガナ = HttpUtility.HtmlEncode(txt旧姓フリガナ.Text);
            int sex = 0;
            if (ddl_性別.SelectedValue.ToString() != "-1")
            {
                sex = Convert.ToInt32(ddl_性別.SelectedValue.ToString());
                if (sex == 1)
                {
                    obj.性別 = true;
                }
                else
                {
                    obj.性別 = false;
                }
            }
            if (txt_生年月日.Text != "")
            {
                DateTime d5;
                try
                {
                    d5 = Convert.ToDateTime(txt_生年月日.Text);
                    obj.生年月日 = d5;
                    DateTime da = DateTime.Now;
                    obj.年齢 = Convert.ToInt32(da.Year - d5.Year);
                }
                catch (Exception ex)
                {
                }
            }
            if (ful_写真.HasFile)
            {
                Bitmap bmp = new Bitmap(ful_写真.FileContent);
                string name = saveImage(bmp);
                Session.Add("imageNew", name);
                obj.写真 = name;
            }
            else
            {
                if (Session["imageOlder"] != null && Session["imageOlder"].ToString() != "")
                {
                    obj.写真 = Session["imageOlder"].ToString();
                }
            }
            if (ddl_国籍.SelectedValue.ToString() != "-1")
            {
                obj.国籍 = Convert.ToInt32(ddl_国籍.SelectedValue.ToString());
            }
            obj.出身地 = HttpUtility.HtmlEncode(txt_出身地.Text.Trim());
            if (ddl血液型コード.SelectedValue.ToString() != "-1")
            {
                obj.血液型コード = ddl血液型コード.SelectedValue.ToString();
            }
            if (ddl血液型名.SelectedValue.ToString() != "-1")
            {
                obj.血液型名 = ddl血液型名.SelectedValue.ToString();
            }
            obj.会社携帯 = HttpUtility.HtmlEncode(txt_会社携帯1.Text.Trim() + "-" + txt_会社携帯2.Text.Trim() + "-" + txt_会社携帯3.Text.Trim());
            obj.会社メールアドレス１ = HttpUtility.HtmlEncode(txt_会社メールアドレス１.Text.Trim());
            obj.その他メールアドレス1 = HttpUtility.HtmlEncode(txt_会社メールアドレス２.Text.Trim());
            obj.趣味 = HttpUtility.HtmlEncode(txt_趣味.Text.Trim());
            obj.外国人登録番号 = HttpUtility.HtmlEncode(txt_外国人登録番号.Text.Trim());
            obj.査証申請地 = HttpUtility.HtmlEncode(txt_査証申請地.Text.Trim());
            if (txt_在留期限.Text.ToString() != "")
            {
                try
                {
                    DateTime d1;
                    d1 = Convert.ToDateTime(txt_在留期限.Text);
                    obj.在留期限 = d1;
                }
                catch
                {
                    obj.在留期限 = null;
                }
            }
            obj.滞在予定期間 = HttpUtility.HtmlEncode(txt_滞在予定期間.Text.Trim());
            obj.パスポート番号 = HttpUtility.HtmlEncode(txt_パスポート番号.Text.Trim());
            if (txt_発行日.Text.ToString() != "")
            {
                try
                {
                    DateTime d2;
                    d2 = Convert.ToDateTime(txt_発行日.Text);
                    obj.発行日 = d2;
                }
                catch
                {
                    obj.発行日 = null;
                }
            }
            if (txt_有効期限.Text.ToString() != "")
            {
                try
                {
                    DateTime d2;
                    d2 = Convert.ToDateTime(txt_有効期限.Text);
                    obj.有効期限 = d2;
                }
                catch
                {
                    obj.有効期限 = null;
                }
            }
            obj.ID番号1 = HttpUtility.HtmlEncode(txt_ID番号.Text.Trim());
            if (txt_ＩＤ番号発行日.Text.ToString() != "")
            {
                try
                {
                    DateTime d3;
                    d3 = Convert.ToDateTime(txt_ＩＤ番号発行日.Text.ToString());
                    obj.ＩＤ番号発行日 = d3;
                }
                catch
                {
                    obj.ＩＤ番号発行日 = null;
                }
            }
            obj.宗教 = HttpUtility.HtmlEncode(txt_宗教.Text.Trim());
            obj.民族 = HttpUtility.HtmlEncode(txt_民族.Text.Trim());
            obj.現住所1 = HttpUtility.HtmlEncode(txt_市民権.Text.Trim());
            if (txt_死亡日.Text.ToString() != "")
            {
                try
                {
                    DateTime d6;
                    d6 = Convert.ToDateTime(txt_死亡日.Text.ToString());
                    obj.死亡日 = d6;
                }
                catch
                {
                    obj.死亡日 = null;
                }
            }
            基本情報Manager frm = new 基本情報Manager();
            obj.廃止区分 = 0;// xet cung kkhi insert hay update (update khong duocthay doi ) chi khi nao xoa tam gan lai bang gia tri khac
            obj.社員分類コード = 3;//ma phan biet loai cong ty nao xet cung su ly sau
            if ((Session["ModeUpdateStaffBasicInfoInput"]) != null)
            {
                if (Session["ModeUpdateStaffBasicInfoInput"].ToString() == "Update")
                {
                    obj.企業ＩＤ = 1;// gan cung ma cong ty su ly sau
                    obj.社員ID = Convert.ToInt32(Session["IDStaffBasicInfoInput"].ToString());// ma nhan vien duoc chuyen qua tu giao dien frmJ_EmpBasicInfo
                }
            }
            // xac dinh ma login de bat id cong ty xet truong hop la update hay insert
            else if ((Session["ModeUpdateStaffBasicInfoInput"]) == null)
            {
                if (Session["役"] != null)
                {
                    int 役 = Convert.ToInt32(Session["役"].ToString());
                    if (役 == 1)
                    {
                        //gan ma cong ty tu dropdownlist khi role =1;
                        if (ddl_企業名.SelectedValue.ToString() != "-1")
                        {
                            obj.企業ＩＤ = Convert.ToInt32(ddl_企業名.SelectedValue.ToString());
                        }
                    }
                    else
                    {
                        if (Session["企業コード_2"] != null)
                        {
                            try
                            {
                                obj.企業ＩＤ = Convert.ToInt32(Session["企業コード_2"].ToString());
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }
            //gan obj vao session de su ly sau ,hien thi cac label, an cac control 
            Session.Add("objStaffBasicInfoInput", obj);
            ShowHiddenForPanel(true);
            ShowHiddenForPanelRoot(false);
            ShowInformationLabel();
        }
    }
    public string saveImage(Bitmap bitmap)//luu image vao bo nho cache
    {
        string tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        string name = "ENZAN-";
        Random random = new Random();
        for (int i = 0; i < 20; i++)
        {
            int index = random.Next(tmp.Length - 1);
            name += tmp[index].ToString();
        }
        string cachePath = Path.Combine(HttpRuntime.CodegenDir, name + ".png");
        Session.Add("cachePathImage", cachePath);
        bitmap.Save(cachePath, ImageFormat.Png);
        return name + ".png";
    }
    public void bind国籍()// hien thi quoc tich.
    {
        try
        {
            frm_HumanBasicInfoManager frm = new frm_HumanBasicInfoManager();
            DataTable dt = frm.get国籍();
            ddl_国籍.DataSource = dt;
            ddl_国籍.DataTextField = "国籍名";
            ddl_国籍.DataValueField = "ID";
            ddl_国籍.DataBind();
            ListItem item = new ListItem("[選択]", "-1");
            item.Selected = true;
            ddl_国籍.Items.Insert(0, item);
        }
        catch { }
    }
    public String GetError(string errorid)//ham lay message loi duoi db
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            return error = dt.Rows[0][2].ToString();
        }
        else
        {
            return error;
        }
    }
    public void CheckUpdate()// ham kiem tra update
    {
        if (Session["ModeUpdateStaffBasicInfoInput"] != null)
        {
            ViewState["css"] = 1;//gan bien de lam bold cac label o mode xac nhan
            dv死亡日.Visible = true;
            btn_戻る.Enabled = true;
            string flag = "";
            if (Session["clearAllMode"] != null)
                flag = Session["clearAllMode"].ToString();// check clear text all in mode update
            btn_次.Enabled = true;
            try
            {
                本社情報Manager manager = new 本社情報Manager();
                基本情報Manager frm = new 基本情報Manager();
                DataTable dt = new DataTable();
                DataTable table = new DataTable();
                基本情報 obj = new 基本情報();
                //  obj.企業ＩＤ = 1;//ma cong ty khi login
                if (Session["IDStaffBasicInfoInput"] != null)
                {
                    obj.社員ID = Convert.ToInt32(Session["IDStaffBasicInfoInput"].ToString());// Lay ma nhan vien tu form frmJ_EmpBasicInfo
                }
                dt = frm.Get基本情報((Int32)obj.社員ID);
                if (flag != "1")
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        obj.人コード = row["人コード"].ToString();
                        obj.姓 = row["姓"].ToString();
                        obj.名 = row["名"].ToString();
                        obj.フリガナ姓 = row["フリガナ姓"].ToString();
                        obj.フリガナ名 = row["フリガナ名"].ToString();
                        obj.英字姓 = row["英字姓"].ToString();
                        ///////////////////////////////////////////////////////////////////////////////////
                        obj.性別 = Convert.ToBoolean(row["性別"].ToString());
                        ///////////////////////////////////////////////////////////////////////////////////
                        obj.英字名 = row["英字名"].ToString();
                        obj.旧漢字 = row["旧姓漢字"].ToString();
                        obj.旧姓フリガナ = row["旧姓フリガナ"].ToString();
                        // su ly  radio button sau
                        obj.生年月日 = Convert.ToDateTime(row["生年月日"].ToString());
                        string img = row["写真"].ToString();

                        if (img != "" && img != null)
                        {
                            // luu session image cu cua nguoi dung truoc do
                            Session.Add("imageOlder", img);
                            Image2.Visible = true;
                            string path = "~/Images/Org_Staff/";
                            Image2.ImageUrl = path + img;
                            Panel1.Visible = true;
                        }
                        if (img == null)
                            Panel1.Visible = false;
                        obj.国籍 = Convert.ToInt32(row["国籍"].ToString());
                        obj.血液型コード = row["出身地"].ToString();
                        obj.血液型コード = row["血液型コード"].ToString();
                        obj.血液型名 = row["血液型名"].ToString();
                        ///////////////////////////////////////////////////////////////////////////////////
                        obj.会社メールアドレス１ = row["会社メールアドレス１"].ToString();
                        obj.その他メールアドレス1 = row["会社メールアドレス２"].ToString();
                        obj.趣味 = row["趣味"].ToString();
                        obj.外国人登録番号 = row["外国人登録番号"].ToString();
                        obj.出身地 = row["出身地"].ToString();
                        ///////////////////////////////////////////////////////////////////////////////////
                        obj.査証申請地 = row["査証申請地"].ToString();
                        obj.ID番号1 = row["ID番号"].ToString();
                        obj.滞在予定期間 = row["滞在予定期間"].ToString();
                        obj.パスポート番号 = row["パスポート番号"].ToString();
                        if (row["発行日"].ToString() != "")
                        {
                            obj.発行日 = Convert.ToDateTime(row["発行日"].ToString());
                        }
                        ///////////////////////////////////////////////////////////////////////////////////
                        if (row["有効期限"].ToString() != "")
                        {
                            obj.有効期限 = Convert.ToDateTime(row["有効期限"].ToString());
                        }
                        if (row["ＩＤ番号発行日"].ToString() != "")
                        {
                            obj.ＩＤ番号発行日 = Convert.ToDateTime(row["ＩＤ番号発行日"].ToString());
                        }
                        obj.宗教 = row["宗教"].ToString();
                        obj.民族 = row["民族"].ToString();
                        ///////////////////////////////////////////////////////////////////////////////////

                        obj.市民権 = row["市民権"].ToString();

                        if (row["死亡日"].ToString() != "")
                        {
                            obj.死亡日 = Convert.ToDateTime(row["死亡日"].ToString());
                        }
                        obj.会社携帯 = row["会社携帯"].ToString();

                        obj.現住所1 = row["市民権"].ToString();
                    }
                    Session.Add("objStaffBasicInfoInput", obj);
                    ShowHiddenForPanel(true);
                    ShowHiddenForPanelRoot(false);
                    ShowInformationLabel();
                }
                Session["clearAllMode"] = null;

            }
            catch (Exception ex) { }
        }
    }
    public void hienThiThongTinUpdate(基本情報 obj)
    {
        txt_人コード.Text = HttpUtility.HtmlDecode(obj.人コード);
        txt_名.Text = HttpUtility.HtmlDecode(obj.名);
        txt_姓.Text = HttpUtility.HtmlDecode(obj.姓);
        txt_フリガナ姓.Text = HttpUtility.HtmlDecode(obj.フリガナ姓);
        txt_フリガナ名.Text = HttpUtility.HtmlDecode(obj.フリガナ名);
        txt_英字姓.Text = HttpUtility.HtmlDecode(obj.英字姓);
        ///////////////////////////////////////////////////////////////////////////////////
        Boolean gioitinh = (Boolean)obj.性別;
        ddl_性別.Items.Remove("-1");

        if (gioitinh)
        {
            ddl_性別.Text = "1";
        }
        else
        {
            ddl_性別.Text = "0";
        }
        ///////////////////////////////////////////////////////////////////////////////////
        txt_英字名.Text = HttpUtility.HtmlDecode(obj.英字名);
        txt旧姓漢字.Text = HttpUtility.HtmlDecode(obj.旧漢字);
        txt旧姓フリガナ.Text = HttpUtility.HtmlDecode(obj.旧姓フリガナ);
        DateTime d1 = (DateTime)obj.生年月日;
        string 生年月日 = d1.ToString("yyyy/MM/dd");
        txt_生年月日.Text = 生年月日;
        ///////////////////////////////////////////////////////////////////////////////////
        string img = obj.写真;
        if (img != "" && img != null)
        {
            // luu session image cu cua nguoi dung truoc do
            Session.Add("imageOlder", img);
            Image2.Visible = true;
            string path = "~/Images/Org_Staff/";
            Image2.ImageUrl = path + img;
            Panel1.Visible = true;
        }
        if (img == null || img == "")
            Panel1.Visible = false;
        ddl_国籍.Items.Remove("-1");
        ddl_国籍.Text = Convert.ToString(obj.国籍);
        txt_出身地.Text = HttpUtility.HtmlDecode(obj.出身地);
        if (obj.血液型コード != null && obj.血液型コード != "")
        {
            ddl血液型コード.Text = HttpUtility.HtmlDecode(obj.血液型コード);
        }
        if (obj.血液型名 != null && obj.血液型名 != "")
        {
            ddl血液型名.Text = HttpUtility.HtmlDecode(Convert.ToString(obj.血液型名));
        }

        ///////////////////////////////////////////////////////////////////////////////////
        txt_会社メールアドレス１.Text = HttpUtility.HtmlDecode(obj.会社メールアドレス１);
        txt_会社メールアドレス２.Text = HttpUtility.HtmlDecode(obj.その他メールアドレス1);
        txt_趣味.Text = HttpUtility.HtmlDecode(obj.趣味);
        ///////////////////////////////////////////////////////////////////////////////////
        if (obj.有効期限.ToString() != "")
        {
            DateTime d5 = (DateTime)obj.有効期限;
            string data = d5.ToString("yyyy/MM/dd");
            txt_有効期限.Text = data;
        }
        txt_パスポート番号.Text = HttpUtility.HtmlDecode(obj.パスポート番号);
        if (obj.発行日.ToString() != "")
        {
            DateTime d5 = (DateTime)obj.発行日;
            string data = d5.ToString("yyyy/MM/dd");
            txt_発行日.Text = data;
        }
        if (obj.ＩＤ番号発行日.ToString() != "")
        {
            DateTime d5 = (DateTime)obj.ＩＤ番号発行日;
            string data = d5.ToString("yyyy/MM/dd");
            txt_ＩＤ番号発行日.Text = data;
        }
        txt_宗教.Text = HttpUtility.HtmlDecode(obj.宗教);
        txt_民族.Text = HttpUtility.HtmlDecode(obj.民族);
        txt_ID番号.Text = HttpUtility.HtmlDecode(obj.ID番号1);

        if (obj.死亡日.ToString() != "")
        {
            DateTime d5 = (DateTime)obj.死亡日;
            string data = d5.ToString("yyyy/MM/dd");

            txt_死亡日.Text = data;
        }
        string phone = obj.会社携帯;
        if (phone != "")
        {
            int fist = phone.IndexOf("-");
            int last = phone.LastIndexOf("-");
            txt_会社携帯1.Text = phone.Substring(0, fist);
            txt_会社携帯2.Text = phone.Substring(fist + 1, (last) - (fist + 1));
            txt_会社携帯3.Text = phone.Substring(last + 1, phone.Length - (last + 1));
        }
        txt_市民権.Text = HttpUtility.HtmlDecode(obj.現住所1);

    }

    protected void validate(object sender, EventArgs e)//ham validate tren server
    {

        CustomValidator1.Validate();

        if (CustomValidator1.IsValid == false)
        {
        }
    }
    public void bind企業名()// hien thi ten cong ty.
    {
        try
        {
            本社情報Manager frm = new 本社情報Manager();
            DataTable dt = frm.sp_frmJ_StaffBasicInfoInput_Getddl_企業名();
            ddl_企業名.DataSource = dt;
            ddl_企業名.DataTextField = "企業名";
            ddl_企業名.DataValueField = "企業ID";
            ddl_企業名.DataBind();
            ListItem item = new ListItem("[選択]", "-1");
            item.Selected = true;
            ddl_企業名.Items.Insert(0, item);
        }
        catch { }
    }
    [WebMethod]
    public static bool IsExisted(string maCongTy, string ID)// phuong thuc  kiem tra 人コード co trung duoi db ko
    {
        var returnVal = false;
        基本情報Manager frm = new 基本情報Manager();
        Int32 i = Convert.ToInt32(ID);
        DataTable table = frm.Check人コード(maCongTy, i);
        if (table.Rows.Count > 0)
        {
            returnVal = true;
        }

        return returnVal;
    }
    [WebMethod]
    public static bool IsExistedcmnd(string cmnd)// phuong thuc  kiem tra  id cmnd co trung duoi db ko
    {
        string id = "" ; 
        if (HttpContext.Current.Session["IDStaffBasicInfoInput"] != null)
        {
            id = (HttpContext.Current.Session["IDSt affBasicInfoInput"].ToString());// Lay ma nhan vien tu form frmJ_EmpBasicInfo

        }
        else
        {
            id = "";
        }
            var returnVal = false;
            基本情報Manager frm = new 基本情報Manager();
            DataTable table = frm.CheckID番号(cmnd, id);

            if (table.Rows[0][0].ToString() != "0")
            {
                returnVal = true;
            }

            return returnVal;
    }
    protected void ShowHiddenForPanel(bool flag)//an hien panel label
    {
        pnl企業名.Visible = flag;
        pnl社員コード.Visible = flag;
        pnl氏名.Visible = flag;
        pnlフリガナ名.Visible = flag;
        pnlフリガナ姓.Visible = flag;
        pnl英字姓.Visible = flag;
        pnl英字名.Visible = flag;
        pnl旧姓.Visible = flag;
        pnlフリガナ.Visible = flag;
        pnl性別.Visible = flag;
        pnl生年月日.Visible = flag;
        pnl写真.Visible = flag;
        pnl国籍.Visible = flag;
        pnl出身地.Visible = flag;
        pnl血液型コード.Visible = flag;
        pnl血液型名.Visible = flag;
        pnl会社携帯.Visible = flag;
        pnl会社メールアドレス.Visible = flag;
        pnlその他メールアドレス.Visible = flag;
        pnl趣味.Visible = flag;
        pnlパスポート番号.Visible = flag;
        pnl発行日.Visible = flag;
        pnl有効期限.Visible = flag;
        pnlID番号.Visible = flag;
        pnlＩＤ番号発行日.Visible = flag;
        pnl宗教.Visible = flag;
        pnl民族.Visible = flag;
        pnl現住所.Visible = flag;
        pnl死亡日.Visible = flag;
        btn_確認.Visible = flag;
        btn_修正.Visible = flag;
        Label1.Visible = flag;
    }
    protected void addCss()
    {// add css bold label cho mode xac nhan
        if (ViewState["css"] != null)
        {
            span1.Attributes.Add("class", "detail-label-bold");
            span2.Attributes.Add("class", "detail-label-bold");
            span3.Attributes.Add("class", "detail-label-bold");
            span4.Attributes.Add("class", "detail-label-bold");
            span5.Attributes.Add("class", "detail-label-bold");
            span6.Attributes.Add("class", "detail-label-bold");
            span7.Attributes.Add("class", "detail-label-bold");
            span8.Attributes.Add("class", "detail-label-bold");
            span9.Attributes.Add("class", "detail-label-bold");
            span10.Attributes.Add("class", "detail-label-bold");
            span11.Attributes.Add("class", "detail-label-bold");
            span12.Attributes.Add("class", "detail-label-bold");
            span13.Attributes.Add("class", "detail-label-bold");
            span14.Attributes.Add("class", "detail-label-bold");
            span15.Attributes.Add("class", "detail-label-bold");
            span16.Attributes.Add("class", "detail-label-bold");
            span17.Attributes.Add("class", "detail-label-bold");
            span18.Attributes.Add("class", "detail-label-bold");
            span19.Attributes.Add("class", "detail-label-bold");
            span20.Attributes.Add("class", "detail-label-bold");
            span21.Attributes.Add("class", "detail-label-bold");
            span22.Attributes.Add("class", "detail-label-bold");
            span23.Attributes.Add("class", "detail-label-bold");
            span24.Attributes.Add("class", "detail-label-bold");
            span25.Attributes.Add("class", "detail-label-bold");
            span26.Attributes.Add("class", "detail-label-bold");
            span27.Attributes.Add("class", "detail-label-bold");
            span28.Attributes.Add("class", "detail-label-bold");
            span29.Attributes.Add("class", "detail-label-bold");
        }
        else if (ViewState["css"] == null)
        {
            span1.Attributes.Remove("class");
            span2.Attributes.Remove("class");
            span3.Attributes.Remove("class");
            span4.Attributes.Remove("class");
            span5.Attributes.Remove("class");
            span6.Attributes.Remove("class");
            span7.Attributes.Remove("class");
            span8.Attributes.Remove("class");
            span9.Attributes.Remove("class");
            span10.Attributes.Remove("class");
            span11.Attributes.Remove("class");
            span12.Attributes.Remove("class");
            span13.Attributes.Remove("class");
            span14.Attributes.Remove("class");
            span15.Attributes.Remove("class");
            span16.Attributes.Remove("class");
            span17.Attributes.Remove("class");
            span18.Attributes.Remove("class");
            span19.Attributes.Remove("class");
            span20.Attributes.Remove("class");
            span21.Attributes.Remove("class");
            span22.Attributes.Remove("class");
            span23.Attributes.Remove("class");
            span24.Attributes.Remove("class");
            span25.Attributes.Remove("class");
            span26.Attributes.Remove("class");
            span27.Attributes.Remove("class");
            span28.Attributes.Remove("class");
            span29.Attributes.Remove("class");
        }
    }

    protected void ShowHiddenForPanelRoot(bool flag)//an hien panel control
    {
        Panel1.Visible = flag;
        pnl企業名1.Visible = flag;
        pnl社員コード1.Visible = flag;
        pnl氏名1.Visible = flag;
        pnlフリガナ名1.Visible = flag;
        pnlフリガナ姓1.Visible = flag;
        pnl英字姓1.Visible = flag;
        pnl英字名1.Visible = flag;
        pnl旧姓1.Visible = flag;
        pnlフリガナ1.Visible = flag;
        pnl性別1.Visible = flag;
        pnl生年月日1.Visible = flag;
        pnl写真1.Visible = flag;
        pnl国籍1.Visible = flag;
        pnl出身地1.Visible = flag;
        pnl血液型コード1.Visible = flag;
        pnl血液型名1.Visible = flag;
        pnl会社携帯1.Visible = flag;
        pnl会社メールアドレス1.Visible = flag;
        pnlその他メールアドレス1.Visible = flag;
        pnl趣味1.Visible = flag;
        pnlパスポート番号1.Visible = flag;
        pnl発行日1.Visible = flag;

        pnl有効期限1.Visible = flag;
        pnlID番号1.Visible = flag;
        pnlＩＤ番号発行日1.Visible = flag;
        pnl宗教1.Visible = flag;
        pnl民族1.Visible = flag;
        pnl現住所1.Visible = flag;
        pnl死亡日1.Visible = flag;
        btn_登録.Visible = flag;
        btn_リセット.Visible = flag;
        lbl.Visible = flag;
    }
    protected void ShowInformationLabel()//hien thi thong tin len label
    {

        if (Session["objStaffBasicInfoInput"] != null)
        {
            addCss();
            ViewState["css"] = null;
            基本情報 obj = (基本情報)Session["objStaffBasicInfoInput"];

            本社情報Manager frm = new 本社情報Manager();

            lbl企業名.Text = ddl_企業名.SelectedItem.Text; ;
            lbl社員コード.Text = HttpUtility.HtmlDecode(obj.人コード);
            lbl氏名.Text = HttpUtility.HtmlDecode(obj.姓) + "&nbsp" + HttpUtility.HtmlDecode(obj.名);
            lblフリガナ姓.Text = HttpUtility.HtmlDecode(obj.フリガナ姓);
            lblフリガナ名.Text = HttpUtility.HtmlDecode(obj.フリガナ名);
            lbl英字姓.Text = HttpUtility.HtmlDecode(obj.英字姓);
            lbl英字名.Text = HttpUtility.HtmlDecode(obj.英字名);
            lbl旧姓.Text = (obj.旧漢字 == "") ? "-" : HttpUtility.HtmlDecode(obj.旧漢字);
            lblフリガナ.Text = (obj.旧姓フリガナ == "") ? "-" : HttpUtility.HtmlDecode(obj.旧姓フリガナ);
            if (obj.性別 == true)
            {
                lbl性別.Text = "女";
            }
            else
            {
                lbl性別.Text = "男";
            }

            if (obj.生年月日 != null)
            {
                DateTime date4 = (DateTime)obj.生年月日;
                string month = "0";
                if (date4.Month < 10)
                {
                    month += date4.Month;
                }
                else
                {
                    month = date4.Month.ToString();
                }
                string day = "0";
                if (date4.Day < 10)
                {
                    day += date4.Day;
                }
                else
                {
                    day = date4.Day.ToString();
                }
                lbl生年月日.Text = date4.Year + "/" + month + "/" + day;
            }
            if (Session["imageOlder"] != null)
            {
                if (Session["imageOlder"].ToString() != "")
                {
                    Image1.ImageUrl = "../ImageHandler.ashx?ImageName=" + Session["imageOlder"].ToString();
                }
            }

            if (Session["imageNew"] != null)
            {
                if (Session["imageNew"].ToString() != "")
                {
                    Image1.ImageUrl = "../ImageHandler.ashx?ImageName=" + Session["imageNew"].ToString();
                }
            }
            else if (Session["imageOlder"] == null && Session["imageNew"] == null)
            {
                Image1.ImageUrl = "../Images/no-image.jpg";
            }

            int quocgia = (Int32)obj.国籍;
            DataTable table = new 基本情報Manager().GetQuocGia(quocgia);

            lbl国籍.Text = table.Rows[0]["国籍名"].ToString();
            lbl出身地.Text = HttpUtility.HtmlDecode(obj.出身地);
            lbl血液型コード.Text = (obj.血液型コード == null) ? "-" : HttpUtility.HtmlDecode(obj.血液型コード);
            lbl血液型名.Text = (obj.血液型名 == null) ? "-" : HttpUtility.HtmlDecode(obj.血液型名);
            lbl会社携帯.Text = HttpUtility.HtmlDecode(obj.会社携帯);
            lbl会社メールアドレス.Text = HttpUtility.HtmlDecode(obj.会社メールアドレス１);
            lblその他メールアドレス.Text = (obj.その他メールアドレス1 == "") ? "-" : HttpUtility.HtmlDecode(obj.その他メールアドレス1);
            lbl趣味.Text = (obj.趣味 == "") ? "-" : HttpUtility.HtmlDecode(obj.趣味);

            lblパスポート番号.Text = (obj.パスポート番号 == "") ? "-" : HttpUtility.HtmlDecode(obj.パスポート番号);

            if (obj.発行日 != null)
            {
                DateTime date1 = (DateTime)obj.発行日;
                string month = "0";
                if (date1.Month < 10)
                {
                    month += date1.Month;
                }
                else
                {
                    month = date1.Month.ToString();
                }
                string day = "0";
                if (date1.Day < 10)
                {
                    day += date1.Day;
                }
                else
                {
                    day = date1.Day.ToString();
                }
                if (obj.発行日.ToString() != "")
                {
                    lbl発行日.Text = date1.Year + "/" + month + "/" + day;
                }

            }
            else
            {
                lbl発行日.Text = "";
            }

            if (obj.有効期限 != null)
            {
                DateTime date1 = (DateTime)obj.有効期限;
                string month = "0";
                if (date1.Month < 10)
                {
                    month += date1.Month;
                }
                else
                {
                    month = date1.Month.ToString();
                }
                string day = "0";
                if (date1.Day < 10)
                {
                    day += date1.Day;
                }
                else
                {
                    day = date1.Day.ToString();
                }
                if (obj.有効期限.ToString()!="")
                {
                    lbl有効期限.Text = date1.Year + "/" + month + "/" + day;
                }   
            }
            else
            {
                lbl有効期限.Text = "-";
            }
            lblID番号.Text = obj.ID番号1;

            if (obj.ＩＤ番号発行日 != null)
            {
                DateTime date2 = (DateTime)obj.ＩＤ番号発行日;
                string month = "0";
                if (date2.Month < 10)
                {
                    month += date2.Month;
                }
                else
                {
                    month = date2.Month.ToString();
                }
                string day = "0";
                if (date2.Day < 10)
                {
                    day += date2.Day;
                }
                else
                {
                    day = date2.Day.ToString();
                }
                    lblＩＤ番号発行日.Text = date2.Year + "/" + month + "/" + day;
            }
            lbl宗教.Text = (obj.宗教 == "") ? "-" : HttpUtility.HtmlDecode(obj.宗教);
            lbl民族.Text = (obj.民族 == "") ? "-" : HttpUtility.HtmlDecode(obj.民族);
            lbl現住所.Text = HttpUtility.HtmlDecode(obj.現住所1);

            if (obj.死亡日 != null)
            {
                DateTime date3 = (DateTime)obj.死亡日;
                string month = "0";
                if (date3.Month < 10)
                {
                    month += date3.Month;
                }
                else
                {
                    month = date3.Month.ToString();
                }
                string day = "0";
                if (date3.Day < 10)
                {
                    day += date3.Day;
                }
                else
                {
                    day = date3.Day.ToString();
                }
                if (obj.死亡日.ToString() != "")
                {
                    lbl死亡日.Text = date3.Year + "/" + month + "/" + day;
                }   
            }
            else
            {
                lbl死亡日.Text = "-";
            } 
        }
    }
    protected void btn_確認_Click(object sender, EventArgs e)//new
    {
        if (CustomValidatorID番号.IsValid)
        {
            基本情報Manager frm = new 基本情報Manager();
            基本情報 obj = null;
            // xac dinh cac mode la insert hay update
            if ((Session["ModeUpdateStaffBasicInfoInput"]) != null)
            {
                if (Session["ModeUpdateStaffBasicInfoInput"].Equals("Update") && Session["objStaffBasicInfoInput"] != null)//mode update
                {
                    obj = (基本情報)Session["objStaffBasicInfoInput"];
                    if (Session["imageOlder"] != null)
                    {
                        string olderPath = Server.MapPath("~/Images/Org_Staff/") + Session["imageOlder"].ToString();
                        if (File.Exists(olderPath))
                        {
                            File.Delete(olderPath);
                        }
                    }
                    frm.Update基本情報(obj);
                    if (obj.写真 != "" && obj.写真 != null)
                    {
                        if (Session["cachePathImage"] != null)
                        {
                            string source = (string)Session["cachePathImage"];

                            string path = Server.MapPath("~/Images/Org_Staff/" + obj.写真);
                            File.Copy(source, path);
                            Session["cachePathImage"] = null;
                        }
                    }
                    Session["clearAllMode"] = null;
                    Session["ModeUpdateStaffBasicInfoInput"] = null;
                    Session["imageNew"] = null;
                    Response.Redirect("frmJ_EmpBasicInfo.aspx");
                }
            }
            else
            {
                if (Session["objStaffBasicInfoInput"] != null)//mode insert
                {
                    obj = (基本情報)Session["objStaffBasicInfoInput"];
                    if (Session["imageNew"] != null && Session["cachePathImage"] != null)
                    {
                        if (Session["cachePathImage"].ToString() != "" && Session["imageNew"].ToString() != "")
                        {
                            string source = (string)Session["cachePathImage"];
                            string path = Server.MapPath("~/Images/Org_Staff/" + Session["imageNew"].ToString());
                            File.Copy(source, path);
                            Session["cachePathImage"] = null;
                            Session["imageNew"] = null;
                        }
                    }
                    DataTable table = frm.Insert_基本情報(obj);
                    ClientScript.RegisterStartupScript(this.GetType(), "fu", "clearAll", false);
                    if (table.Rows.Count > 0)
                    {
                        int id = Convert.ToInt32(table.Rows[0][0].ToString());
                        //gui khoa chinh ma nhan vien cho cac trang tiep theo dong thoi gui mode la insert cho cac form tiep theo
                        Session.Add("IdEmp", id);
                        Session.Add("ModeUpdateStaffEnterInput", "Insert");
                        Session.Add("ModeUpdateStaffDegreeByCompInput", "Insert");
                        Session["ModeUpdateStaffCareerInput"] = "Insert";
                        Session["ModeUpdateStaffContractTypeInput"] = "Insert";
                        Session["objStaffBasicInfoInput"] = null;
                        Session["imageNew"] = null;
                        txt_人コード.Text = "";
                        Response.Redirect("frmJ_StaffEnterInput.aspx");
                        return;
                    }
                }
            }
        }
    }
    protected void btn_修正_Click(object sender, EventArgs e)
    {
        addCss();
        flg2.Value = "0";
        ShowHiddenForPanelRoot(true);
        ShowHiddenForPanel(false);
        if (Session["ModeUpdateStaffBasicInfoInput"] != null)
        {
            基本情報 obj = (基本情報)Session["objStaffBasicInfoInput"];
            hienThiThongTinUpdate(obj);
        }
        if (Session["imageOlder"] != null)
        {
            if (Session["imageOlder"].ToString() != "")
            {
                Image2.ImageUrl = "../ImageHandler.ashx?ImageName=" + Session["imageOlder"].ToString();
                Image2.Visible = true;
                Panel1.Visible = true;
            }
        }
        if (Session["imageNew"] != null)
        {
            if (Session["imageNew"].ToString() != "")
            {
                Image2.ImageUrl = "../ImageHandler.ashx?ImageName=" + Session["imageNew"].ToString();
                Image2.Visible = true;
                Panel1.Visible = true;
            }
        }
        else if (Session["imageNew"] == null && Session["imageOlder"] == null)
        {
            Panel1.Visible = false;
        }
    }
    protected void Button除く_Click(object sender, EventArgs e)
    {
        Session["imageOlder"] = null;
        Session["imageNew"] = null;
        Panel1.Visible = false;
    }
    protected void txt_ID番号_TextChanged(object sender, EventArgs e)
    {
        CustomValidatorID番号.Validate();

        if (CustomValidatorID番号.IsValid == false)
        {

        }

    }
    protected void CustomValidatorID番号_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string id = "";
        if (HttpContext.Current.Session["IDStaffBasicInfoInput"] != null)
        {
            id = (HttpContext.Current.Session["IDStaffBasicInfoInput"].ToString());// Lay ma nhan vien tu form frmJ_EmpBasicInfo

        }
        else
        {
            id = "";
        }
        基本情報Manager frm = new 基本情報Manager();
        DataTable table = frm.CheckID番号(txt_ID番号.Text, id);

        if (table.Rows[0][0].ToString() != "0")
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }
    protected void CustomValidator13_ServerValidate1(object source, ServerValidateEventArgs args)
    {
        email1.Value = txt_会社メールアドレス１.Text;
        args.IsValid = checkEmail();
    }
    private bool checkEmail()
    {
        string id = "";
        if (HttpContext.Current.Session["IDStaffBasicInfoInput"] != null)
        {
            id = (HttpContext.Current.Session["IDStaffBasicInfoInput"].ToString());// Lay ma nhan vien tu form frmJ_EmpBasicInfo

        }
        else
        {
            id = "";
        }
        基本情報Manager frm = new 基本情報Manager();
        DataTable table = frm.checkEmailExists("基本情報", id, txt_会社メールアドレス１.Text, "会社メールアドレス１", "社員ID");

        if (table.Rows[0][0].ToString() != "0")
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    protected void CustomValidator15_ServerValidate(object source, ServerValidateEventArgs args)
    {
        email2.Value = txt_会社メールアドレス２.Text;
        args.IsValid = checkEmail();
    }
}